/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2015-07-29     Arda.Fu      first implementation
 */
#include <stdint.h>
#include <rtthread.h>
#include <rtdevice.h>
#include "sal_socket.h"
#include "netdev.h"
#include "mqtt.h"

#define ESP8266_EN_PIN 57

int main(void)
{
    rt_pin_mode(ESP8266_EN_PIN, PIN_MODE_OUTPUT);
    rt_pin_write(ESP8266_EN_PIN, PIN_HIGH);

    struct netdev * dev1 = netdev_get_by_family(AF_AT);
    while (1)
    {
        if (netdev_is_internet_up(dev1) > 0)
        {
            int mqtt_code = mqtt_start();
            if (mqtt_code != 0)
            {
                rt_kprintf("mqtt connect failed,errcode:%s", mqtt_code);
            }
            break;
        }
        rt_thread_mdelay(1000);
    }

    return RT_EOK;
}

